var app = getApp();
Page({
  data: {
    info:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var user_id = wx.getStorageSync("user_id");
    var order_id = options.order_id
    this.setData({
      order_id:order_id
    })
    if(!user_id){
      wx.navigateTo({
        url: '/pages/login/login'
      });
    }else{
      this.getYdzwOrderInfo();
      this.getReward();
    }
  },

  /**
   * 获取订单列表
   */
  getYdzwOrderInfo: function () {
    let _this = this;
    app.visit('drinker/getYdzwOrderInfo', {
      order_id:_this.data.order_id
    }, '',function (result) {
      console.log("订单列表", result);
      _this.setData({
        info:result.data
      });
    });
  },

  /**
   * 获取打赏信息
   */
  getReward: function () {
    let _this = this;
    app.visit('drinker/getReward', {}, '',function (result) {
      console.log("打赏", result);
      _this.setData({
        reward:result.data
      });
    });
  },

  jmds:function(){
    var t = this
    var ds_price = t.data.reward.price;
    wx.showModal({
      title: '提示',
      content: '确认打赏酒妹吗',
      success: function (res) {
        if (res.confirm) {//这里是点击了确定以后
          wx.showLoading({ title: '正在处理...', });
          app.visit('drinker/setRewardOrder', {
            ds_price:ds_price,
            user_id: wx.getStorageSync("user_id"),
            order_id:t.data.order_id
          }, 'POST',function (result) {
            console.error('支付',result);
            if(result.code == 0){
              // 发起微信支付
              wx.requestPayment({
                timeStamp: result.data.payTimeStamp,
                nonceStr: result.data.paynonceStr,
                package: result.data.payPackage,
                signType: 'RSA',
                paySign: result.data.paySign,
                success: function (res) {
                  wx.showToast({
                    title: '打赏成功',
                    icon: 'none',
                    success: function () {
                      setTimeout(function () {
                        wx.hideToast();
                      }, 1e3);
                    }
                  })
                }
              });
            }else{
              app.myToast('调取支付失败')
            }
            wx.hideLoading();
          });
        } else {//这里是点击了取消以后
          console.log('用户点击取消')
        }
      }
    })
  },

  shangjia:function (e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: "../new/shangjia?id="+id
    });
  }

})